The Spring Framework - Reference Documentation
Total Page:16
File Type:pdf, Size:1020Kb
The Spring Framework - Reference Documentation Version 2.5.6 Copyright © 2004-2008 Rod Johnson, Juergen Hoeller, Alef Arendsen, Colin Sampaleanu, Rob Harrop, Thomas Risberg, Darren Davison, Dmitriy Kopylenko, Mark Pollack, Thierry Templier, Erwin Vervaet, Portia Tung, Ben Hale, Adrian Colyer, John Lewis, Costin Leau, Mark Fisher, Sam Brannen, Ramnivas Laddad, Arjen Poutsma Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically. Preface................................................................................................................................................xv 1.Introduction...................................................................................................................................16 1.1.Overview..............................................................................................................................16 1.2.Usagescenarios ....................................................................................................................18 2. What's new in Spring 2.0 and 2.5? ................................................................................................. 21 2.1.Introduction ..........................................................................................................................21 2.2. The Inversion of Control (IoC) container ................................................................................ 21 2.2.1.Newbeanscopes ........................................................................................................21 2.2.2.EasierXMLconfiguration...........................................................................................22 2.2.3.ExtensibleXMLauthoring ..........................................................................................22 2.2.4.Annotation-drivenconfiguration..................................................................................22 2.2.5.Autodetectingcomponentsintheclasspath .................................................................. 22 2.3.AspectOrientedProgramming(AOP) ....................................................................................23 2.3.1.EasierAOPXMLconfiguration ..................................................................................23 2.3.2.Supportfor@AspectJaspects .....................................................................................23 2.3.3. Support for bean name pointcut element ...................................................................... 23 2.3.4.SupportforAspectJload-timeweaving ........................................................................ 23 2.4.TheMiddleTier ....................................................................................................................23 2.4.1. Easier configuration of declarative transactions in XML ............................................... 23 2.4.2.FullWebSpheretransactionmanagementsupport ......................................................... 24 2.4.3.JPA ...........................................................................................................................24 2.4.4.AsynchronousJMS.....................................................................................................24 2.4.5.JDBC ........................................................................................................................24 2.5.TheWebTier........................................................................................................................25 2.5.1.SensibledefaultinginSpringMVC ............................................................................. 25 2.5.2.Portletframework.......................................................................................................25 2.5.3.Annotation-basedcontrollers.......................................................................................25 2.5.4. A form tag library for Spring MVC ............................................................................. 25 2.5.5.Tiles2support ...........................................................................................................25 2.5.6.JSF1.2support ..........................................................................................................26 2.5.7.JAX-WSsupport ........................................................................................................26 2.6.Everythingelse .....................................................................................................................26 2.6.1.Dynamiclanguagesupport ..........................................................................................26 2.6.2.Enhancedtestingsupport ............................................................................................26 2.6.3.JMXsupport ..............................................................................................................26 2.6.4. Deploying a Spring application context as JCA adapter ................................................. 27 2.6.5.Taskscheduling .........................................................................................................27 2.6.6.Java5(Tiger)support .................................................................................................27 2.7.MigratingtoSpring2.5..........................................................................................................27 2.7.1.Changes.....................................................................................................................28 2.8.Updatedsampleapplications ..................................................................................................30 2.9.Improveddocumentation .......................................................................................................30 I.CoreTechnologies............................................................................................................................31 3.TheIoCcontainer ..................................................................................................................32 3.1.Introduction ..................................................................................................................32 3.2.Basics-containersandbeans ......................................................................................... 32 3.2.1.Thecontainer .....................................................................................................33 3.2.2.Instantiatingacontainer ......................................................................................34 3.2.3.Thebeans ..........................................................................................................35 3.2.4.Usingthecontainer .............................................................................................39 3.3.Dependencies................................................................................................................40 3.3.1.Injectingdependencies........................................................................................40 Spring Framework (2.5.6) ii The Spring Framework - Reference Documentation 3.3.2.Dependenciesandconfigurationindetail ............................................................. 45 3.3.3.Usingdepends-on ..............................................................................................54 3.3.4.Lazily-instantiatedbeans.....................................................................................54 3.3.5.Autowiringcollaborators ....................................................................................55 3.3.6.Checkingfordependencies..................................................................................57 3.3.7.MethodInjection ................................................................................................58 3.4.Beanscopes ..................................................................................................................61 3.4.1.Thesingletonscope ............................................................................................62 3.4.2.Theprototypescope ...........................................................................................63 3.4.3.Singletonbeanswithprototype-beandependencies ............................................... 64 3.4.4.Theotherscopes.................................................................................................64 3.4.5.Customscopes ...................................................................................................68 3.5. Customizing the nature of a bean .................................................................................... 70 3.5.1.Lifecyclecallbacks .............................................................................................70 3.5.2.Knowingwhoyouare .........................................................................................74 3.6.Beandefinitioninheritance ............................................................................................76 3.7.Containerextensionpoints .............................................................................................77 3.7.1.Customizingbeansusing BeanPostProcessors ....................................................78 3.7.2.Customizingconfigurationmetadatawith BeanFactoryPostProcessors ............... 80 3.7.3.Customizinginstantiationlogicusing